package com.coconet.gas.constant.factory.impl;

/**
 * Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



import com.coconet.gas.cache.Cache;
import com.coconet.gas.constant.factory.IConstantFactory;
import com.coconet.gas.dao.SysUserRoleMapper;
import com.coconet.gas.until.SpringContextHolder;
import com.coconet.gas.vo.dw.SysUserRole;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

/**
 * 常量的生产工厂
 *
 * @author fengshuonan
 * @date 2017年2月13日 下午10:55:21
 */
@Component
@DependsOn("springContextHolder")
public class ConstantFactory implements IConstantFactory {

	//private SysCompanyMapper sysCompanyMapper = SpringContextHolder.getBean(SysCompanyMapper.class);
	//private DeviceTypeMapper deTypeMapper = SpringContextHolder.getBean(DeviceTypeMapper.class);
	private SysUserRoleMapper surmapper = SpringContextHolder.getBean(SysUserRoleMapper.class);
	//private SlaveMapper smapper = SpringContextHolder.getBean(SlaveMapper.class);
	//private SlavePassMapper spmapper = SpringContextHolder.getBean(SlavePassMapper.class);
	//private DeviceMapper dmapper = SpringContextHolder.getBean(DeviceMapper.class);

	public static IConstantFactory me() {
		return SpringContextHolder.getBean("constantFactory");
	}

	@Override
	@Cacheable(value = Cache.CONSTANT, key = "#inCode")
	public String getExCodeByInCode(String inCode) {
		/*// TODO Auto-generated method stub
		DeviceType dt = new DeviceType();
		dt.setInCode(inCode);
		List<DeviceType> dtLi = deTypeMapper.select(dt);
		if (!(dtLi.size() == 0)) {
			return dtLi.get(0).getExCode();
		}*/
		return null;

	}

	@Override
	public String getRoleIdByuser(String userName) {
		// TODO Auto-generated method stub
		SysUserRole sur = new SysUserRole();
		sur.setUserId(userName);
		surmapper.selectOne(sur);
		return surmapper.selectOne(sur).getRoleId();
	}

	@Override
	public String getCnameByCid(String cid) {
		/*// TODO Auto-generated method stub
		String cname = "";
		try {
			cname = sysCompanyMapper.selectByPrimaryKey(cid).getComName();

		} catch (Exception e) {
			// TODO: handle exception
			cname = "系统根用户组";
		}
		return cname;*/
		return null;
	}


}
